package com.gouwudai.gobbs.common;

import java.io.File;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.gouwudai.gobbs.html.HtmlConst;
import com.gouwudai.gobbs.pojo.TbbsAffiche;
import com.gouwudai.gobbs.pojo.TbbsArea;
import com.gouwudai.gobbs.pojo.TbbsContentFilter;
import com.gouwudai.gobbs.pojo.TbbsDictParam;
import com.gouwudai.gobbs.pojo.TbbsGrade;
import com.gouwudai.gobbs.pojo.TbbsMasterGrade;
import com.gouwudai.gobbs.pojo.TbbsTopic;
import com.gouwudai.gobbs.pojo.TbbsTopicBuy;
import com.gouwudai.gobbs.pojo.TbbsTopicContent;
import com.gouwudai.gobbs.pojo.TbbsTopicRe;
import com.gouwudai.gobbs.pojo.TbbsUserInfo;
import com.gouwudai.gobbs.service.IAfficheService;
import com.gouwudai.gobbs.service.IAreaService;
import com.gouwudai.gobbs.service.IClassService;
import com.gouwudai.gobbs.service.IContentFilterService;
import com.gouwudai.gobbs.service.IDictParamService;
import com.gouwudai.gobbs.service.IMasterGradeService;
import com.gouwudai.gobbs.service.ITopicBuyService;
import com.gouwudai.gobbs.service.ITopicContentService;
import com.gouwudai.gobbs.service.ITopicReService;
import com.gouwudai.gobbs.service.IUserGradeService;
import com.gouwudai.gobbs.service.IUserService;
import com.litt.core.cache.OSCacheManager;
import com.litt.core.common.BeanManager;
import com.litt.core.common.Utility;
import com.litt.core.common.XMLConfig;
import com.litt.core.exception.BusiException;
import com.litt.core.file.OnlyExt;


/**
 * 
 * <pre>
 *  Title: 通用业务辅助类
 *  Description: 通用业务辅助类  
 * </pre>
 * 
 * @author <a href="mailto:littcai@hotmail.com">空心大白菜</a>
 * @date 2007-4-28
 * @version 1.0
 * <pre>
 * 修改记录
 *    修改后版本:     修改人：  修改日期:     修改内容: 
 * </pre>
 */
public class Arguments {
	
	private static final Log logger = LogFactory.getLog(Arguments.class);	
	
	public static String runningPath; //网站运行根目录，实际路径
    public static String contentPath; //网站运行WebContent根目录，相对路径
	public static String userHeadsPath; //用户头像存放路径
	
	/**
     * WebContent的根目录的绝对路径，所有要取运行时绝对路径的话都从这个方法取.
     * 
     * @return String
     * 
     * @see 系统初始化的时候会将绝对路径赋值到runningPath属性中，如果没有的话则从当前运行的类加载路径中去获取。
     */
	public static String getRootPath()
	{		
		if(runningPath!=null&&!runningPath.trim().equals(""))
			return runningPath;
		else
			return Thread.currentThread().getContextClassLoader().getResource("").getPath();
	}
    
    /**
     * WebContent的根目录的相对路径，所有要取运行时相对路径的话都从这个方法取.
     * 
     * @return String
     * 
     * @see 系统初始化的时候会将绝对路径赋值到contentPath属性中，如果没有的话则为"/"。
     */
    public static String getContentPath()
    {       
        if(contentPath!=null&&!contentPath.trim().equals(""))
            return contentPath;
        else
            return "/";
    }    
	
    /**
     * 获得用户头像存放绝对路径.
     * 
     * @return String
     * 
     * @throws BusiException
     */
	public static String getUserHeadsPath() throws BusiException
	{		
		if(userHeadsPath==null&&userHeadsPath.trim().equals(""))
        {
            userHeadsPath = getRootPath()+XMLConfig.getValue("user-heads-path");
        }			
		return userHeadsPath;        		
	}	
	
	/************ 统一存放静态全局对象  ******************/
	

	/****************************************/

	public static StringBuilder newStringBuilder()
	{
		StringBuilder sb = new StringBuilder(200);
		sb.append("<option value=\"\">请选择</option>");
		return sb;
	}

	public static void appendOptions(StringBuilder sb, int value, String text, int defvalue)
	{
		sb.append("<option");
		sb.append((defvalue == value) ? " selected" : "");
		sb.append(" value=" + value + ">");
		sb.append(text);
		sb.append("</option>");
	}

	public static void appendOptions(StringBuilder sb, Integer value, String text, Integer defvalue)
	{
		sb.append("<option");
		if ((defvalue != null) && (defvalue.equals(value)))
			sb.append(" selected");
		sb.append(" value=" + value + ">");
		sb.append(text);
		sb.append("</option>");
	}

	public static void appendOptions(StringBuilder sb, int value, String text, Integer defvalue)
	{
		sb.append("<option");
		if ((defvalue != null) && (defvalue.intValue() == value))
			sb.append(" selected");
		sb.append(" value=" + value + ">");
		sb.append(text);
		sb.append("</option>");
	}

	public static void appendOptions(StringBuilder sb, String value, String text, String defvalue)
	{
		sb.append("<option");
		if (defvalue != null)
			sb.append((value.trim().compareTo(defvalue.trim()) == 0) ? " selected" : "");
		sb.append(" value=\"" + value + "\">");
		sb.append(text);
		sb.append("</option>");
	}
	
/*********************** 公用超链的封装 *********************************/
	
	/**
	 * 用户信息的链接，显示用户登陆ID
	 */
	public static String getUserInfoLink(String loginId)
	{
		if(loginId==null||loginId.equals(""))
			return "";
		StringBuilder sb = new StringBuilder("<a href=\"user_info.jsp?loginId=");
		sb.append(loginId);
		sb.append("\">");
		sb.append(loginId);
		sb.append("</a>");
		return sb.toString();
	}

	/**
	 * 用户信息的链接，显示用户登陆ID
	 */
	public static String getUserInfoLink(Integer userId,String loginId)
	{
		if(loginId==null||loginId.equals(""))
			return "";
		if(userId==null||userId.intValue()==0)
			return "loginId";
		StringBuilder sb = new StringBuilder("<a href=\"user_info.jsp?userId=");
		sb.append(userId);
		sb.append("\">");
		sb.append(loginId);
		sb.append("</a>");
		return sb.toString();
	}
	
	/**
	 * 用户信息的链接，显示用户登陆ID
	 * 判断用户是否已逻辑删除，已删除则不做链接
	 */
	public static String getUserInfoLink(Integer userId,String loginId,boolean isDel)
	{
		if(loginId==null||loginId.equals(""))
			return "";
		if(userId==null||userId.intValue()==0)
			return loginId;
		
		StringBuilder sb = new StringBuilder(200);
		if(isDel)
		{			
			sb.append("<font color=\"#aaaaaa\">");
            sb.append(loginId);
            sb.append("</font>");
		}	
		else
		{
			sb.append("<a href=\"user_info.jsp?userId=");
			sb.append(userId);
			sb.append("\">");
			sb.append(loginId);
			sb.append("</a>");
		}
		return sb.toString();
	}
	
	/**
	 * 用户信息的链接,显示用户昵称，TITLE为用户登陆ID
	 * 判断用户是否已逻辑删除，已删除则不做链接
	 */
	public static String getUserInfoLink(Integer userId,String loginId,String userName,Boolean isDel)
	{
		if(loginId==null||loginId.equals(""))
			return "过客";
		if(userId==null||userId.intValue()==0)
			return loginId;
		
		StringBuilder sb = new StringBuilder(200);
		if(isDel!=null&&isDel.booleanValue())
		{			
			sb.append("<font color=\"#aaaaaa\">");
            sb.append(loginId);
            sb.append("</font>");
		}	
		else
		{
			sb.append("<a href=\"user_info.jsp?userId=");
			sb.append(userId);
			sb.append("\" title=\"");
			sb.append(loginId);
			sb.append("\">");
			sb.append(userName);
			sb.append("</a>");
		}
		return sb.toString();
	}
	
	/**
	 * 用户头像的链接封装
	 * @param personalPic
	 * @return
	 */
	public static String getUserHeadLink(String personalPic)
	{
		if(personalPic==null)
			return "";
		StringBuilder sb = new StringBuilder(200);
		sb.append("<img src=\"");
		sb.append(personalPic);
		sb.append("\" alt=\"图片地址无效\" border=\"0\" align=\"absmiddle\"  onload=\"javascript:if(this.width > 120){this.width = 120};\">");
		return sb.toString();		
	}
	
	/**
	 * 用户信息的链接（图片链接）
	 * @param userId
	 * @return
	 */
	public static String getUserInfoPicLink(Integer userId)
	{
		StringBuilder sb = new StringBuilder(200);
		sb.append("<a href=\"user_info.jsp?userId=");
		sb.append(userId);
		sb.append("\"  target=\"_blank\"><img alt=\"查看用户信息\" src=\"images/pages/2.gif\" border=\"0\" /></a>");
		return sb.toString();
	}
	
	/**
	 * 用户个人主页的链接封装
	 * @param personalWeb
	 * @return
	 */
	public static String getUserWebLink(String personalWeb)
	{
		if(personalWeb==null||personalWeb.trim().equals(""))
			return "";
		StringBuilder sb = new StringBuilder(200);
		sb.append("<a href=\"http://");
    	sb.append(personalWeb);
    	sb.append("\" target=\"_blank\"><img alt=\"查看个人主页\" src=\"images/pages/1.gif\" border=\"0\" /></a>");
    	return sb.toString();	
	}
	
	/**
	 * 用户电子邮件的链接封装
	 * @param userId
	 * @return
	 */
	public static String getUserEmailLink(Integer userId)
	{
		//是否完全保密和是否为好友在弹出页面判断		
		StringBuilder sb = new StringBuilder(200);
		sb.append("<a onClick=\"return openPop(this,500,400,100,200);\" ");
		sb.append(" href=\"topic_email_send.jsp?userId=");
		sb.append(userId);
		sb.append("\" target=\"_self\"><img alt=\"给用户发送Email\" src=\"images/pages/3.gif\" border=\"0\" /></a>");
    	return sb.toString();	
	}	
	
	/**
	 * 加当前用户为好友
	 * @param userId
	 * @return
	 */
	public static String getAddFriendLink(Integer userId)
	{
		StringBuilder sb = new StringBuilder(200); 
		sb.append("<a onClick=\"return openPop(this,700,500,100,200);\" ");
        sb.append(" href=\"user_friends_add.jsp?userId=");        
        sb.append(userId);        
        sb.append("\" target=\"_blank\"><img src=\"images/pages/5.gif\" border=\"0\"/></a>");
        return sb.toString();	
	}
	
	/**
	 * 发送短消息
	 * @param takeUser
	 * @return
	 */
	public static String getSendMessageLink(String loginId)
	{
		StringBuilder sb = new StringBuilder(200); 
        sb.append("<a onClick=\"return openPop(this,700,500,100,200);\" ");
        sb.append(" href=\"user_write.jsp?takeUser=");
        sb.append(loginId);     
        sb.append("\" target=\"_blank\"><img src=\"images/pages/4.gif\" border=\"0\"/></a>");
        return sb.toString();	
	}	
	
	/**
	 * 回复主题的链接（图片链接）
	 * @param classId
	 * @param topicId
	 * @param TopicReId
	 * @return
	 */
	public static String getReTopicLink(Integer classId,Integer topicId,Integer TopicReId)
	{
		StringBuilder sb = new StringBuilder(200); 
		sb.append("<a href=\"topic_re.jsp?classId=");
    	sb.append(classId);
    	sb.append("&topicId=");
    	sb.append(topicId);
    	sb.append("&topicReId=");
    	sb.append(TopicReId);
    	sb.append("&action=re\" target=\"_self\"><img alt=\"回复主题\" src=\"images/pages/7.gif\" border=\"0\" /></a>");
    	return sb.toString();	
	}
	
	/**
	 * 回复+引用回复的链接（图片链接）
	 * @param classId
	 * @param topicId
	 * @param TopicReId
	 * @return
	 */
	public static String getQuoteTopicLink(Integer classId,Integer topicId,Integer TopicReId)
	{
		StringBuilder sb = new StringBuilder(200); 
		sb.append("<a href=\"topic_re.jsp?classId=");
    	sb.append(classId);
    	sb.append("&topicId=");
    	sb.append(topicId);
    	sb.append("&topicReId=");
    	sb.append(TopicReId);
    	sb.append("&action=quote\" target=\"_self\"><img alt=\"引用并回复主题\" src=\"images/pages/8.gif\" border=\"0\" /></a>");
    	return sb.toString();	
	}	
	
	/**
	 * 显示回复内容
	 * @param //当前用户的类型，-1：游客，0：普通，1:发帖人，2：版主
	 * @param reUserInfo 
	 * @param topicReId
	 * @param rePro
	 * @param reIsDel
	 * @return
	 * @throws Exception
	 */
	public static String getTopicReContent(int operatorType,TbbsUserInfo reUserInfo,Integer topicReId,Integer rePro,Boolean reIsDel) throws Exception
	{
		StringBuilder sb = new StringBuilder(500);
		sb.append("<DIV class=\"content\">");
		//读取回复内容
		ITopicContentService topicContentService = (ITopicContentService)BeanManager.getBean("topicContentService");
		TbbsTopicContent tbbsTopicContent = topicContentService.load(topicReId);
		String content = tbbsTopicContent.getContent();
        //内容编码
        if(content.length()<1)
        {
        	content = "<font color=\"#cccccc\">这头懒 ^&^ , 啥也没写 ^_^</font>";
        }
        else
        {	
	        if(tbbsTopicContent.getIsRicheditor().intValue()==0)   //UBB代码
            {
                //content = EncodeString.htmlEncoder(content);   //HTML编码,存数据库前就已经编码了，所以此地去掉  
                content = EncodeString.ubbEncoder(content);      //UBB编码
            }
			  
        }
        //判断回复的属性     
        sb.append(content);
 
        int contentCopyright = tbbsTopicContent.getContentCopyright();
        boolean contentUserPen = tbbsTopicContent.getContentUserPen();
        if(contentCopyright==1)	//1.本站独享
        {
        	sb.append("<hr width=\"100%\" size=\"1\" noshade=\"noshade\" />");
            sb.append("作者声明：该文版权归作者个人所有，本站享有独家网络发表权，其他网站、媒体未经许可，不得以任何形式转载！");            
        }
        else if(contentCopyright==2)	//2.网络共享 
        {
        	sb.append("<hr width=\"100%\" size=\"1\" noshade=\"noshade\" />");
            sb.append("作者声明：该文版权为网络共享，大家喜欢的话可以任意转载，传抄……");            
        }
        else if(contentCopyright==3)	//3.非商业性共享
        {
        	sb.append("<hr width=\"100%\" size=\"1\" noshade=\"noshade\" />");
            sb.append("作者声明：该文在未经商业用途的情况下，可任意转载，传抄……");            
        }
        if(contentUserPen)
        {	
        	String personalSign = reUserInfo.getPersonalSign();
        	if(!personalSign.trim().equals(""))
	        {
	        	//personalSign = EncodeString.htmlEncoder(personalSign);
	        	//personalSign = EncodeString.ubbEncoder(personalSign);
		        sb.append("<hr width=\"100%\" size=\"1\" noshade=\"noshade\" />");
		        sb.append(personalSign);
	        }    
        }
        sb.append("</DIV>");
        return sb.toString();	
	}
	
	/**
	 * 显示主题内容
	 * @param operatorType 当前用户的类型，-1：游客，0：普通，1:发帖人，2：版主
	 * @param tbbsUserInfo	
	 * @param tbbsTopic
	 * @param tbbsTopicRe
	 * @return
	 */
	public static String getTopicContent(int operatorType,TbbsUserInfo currentUserInfo,TbbsTopic tbbsTopic,TbbsTopicRe tbbsTopicRe) throws Exception
	{		
		Integer currentUserId = new Integer(0);
		BigDecimal currentUserMark = new BigDecimal(0);
		String personalSign = "";
		if(currentUserInfo!=null)
		{
			currentUserId = currentUserInfo.getUserId();
			currentUserMark = currentUserInfo.getUserMark();
			personalSign = currentUserInfo.getPersonalSign();
		}	
		
		int topicId = tbbsTopic.getTopicId().intValue();			
		int topicPro = tbbsTopic.getTopicPro().intValue();
		int topicType = tbbsTopic.getTopicType().intValue();
		BigDecimal topicTypeNum = tbbsTopic.getTopicTypeNum();
		int topicReId = tbbsTopicRe.getTopicReId().intValue();
		boolean reIsDel = tbbsTopicRe.getReIsDel().booleanValue();	
		
		StringBuilder sb = new StringBuilder(500);
		sb.append("<DIV class=\"content\">");
		//内容编码
		//读取回复内容
		ITopicContentService topicContentService = (ITopicContentService)BeanManager.getBean("topicContentService");
		TbbsTopicContent tbbsTopicContent = topicContentService.load(topicReId);
		String content = tbbsTopicContent.getContent();	
		int contentLen = content.length();	//原始内容长度，如果为0则下面就不需要编码了
        if(contentLen<1)
        {
        	content = "<font color=\"#cccccc\">这头懒 ^&^ , 啥也没写 ^_^</font>";
        }
        else
        {	
            if(tbbsTopicContent.getIsRicheditor().intValue()==0)   //UBB代码
            {
                //content = EncodeString.htmlEncoder(content);   //HTML编码,存数据库前就已经编码了，所以此地去掉  
    			content = EncodeString.ubbEncoder(content);      //UBB编码
            }    
        }        
        if(operatorType!=1&&operatorType!=2) //当前主题的内容，如果是积分/金钱帖，需要判断当前用户是否为帖子的主人或版主
		{	
        	if(topicType==2)	//积分浏览
			{			
				if(currentUserMark.subtract(topicTypeNum).doubleValue()<0)
				{
						StringBuilder temp = new StringBuilder(200);
						temp.append("<table width=\"80%\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\"bg1\">");
						temp.append("<tr class=\"tab1\"><td>");
						temp.append("<img border=\"0\" alt=\"积分贴 " + topicTypeNum + "\" src=\"images/topicPro/mark.gif\" align=\"absmiddle\" /> <strong>积分浏览贴</strong>");
						temp.append("</td></tr>");
						temp.append("<tr class=\"tab3\"><td>");
						temp.append("浏览本贴隐藏内容所需积分>="+topicTypeNum+",您的积分不够，无法浏览本贴隐藏内容！");
						temp.append("</td></tr>");
						temp.append("</table>");	
						//隐藏内容
						if(contentLen>0&&content.indexOf("[tcontent]")>=0)
							content = EncodeString.ubbPattern(content,"\\[tcontent\\](.*?)\\[/tcontent\\]",temp.toString()); 
				}
				else
				{					
					if(content.indexOf("[tcontent]")>=0)
	                {	
	    	            content = content.replaceAll("\\[tcontent\\]","");	    	           
	    	     	    content = content.replaceAll("\\[/tcontent\\]","");
	                }
				}	
			}	
			else if(topicType==3)	//金币购买
			{				
				BigDecimal currenyPay = new BigDecimal(0);
				if(currentUserId.intValue()>0)	//已登陆的用户才需要判断是否购买过
				{
					ITopicBuyService topicBuyService = (ITopicBuyService)BeanManager.getBean("topicBuyService");					
					TbbsTopicBuy tbbsTopicBuy = topicBuyService.loadByTopicUser(topicId, currentUserId);					
					if(tbbsTopicBuy!=null)	//已经购买过
						currenyPay = tbbsTopicBuy.getPayMoney();
				}	
				if(topicTypeNum.subtract(currenyPay).doubleValue()<=0)	//付款额大于等于帖子需要的金币数
				{							                
							sb.append("<table width=\"280\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\"bg1\">");
			                sb.append("<tr class=\"tab1\"><td>");
			                sb.append("<img border=\"0\" alt=\"购买帖,所需金币 " + topicTypeNum + "\" src=\"images/topicPro/money.gif\" align=\"absmiddle\" /> <strong>购买贴</strong>");
			                sb.append("</td></tr>");
			                sb.append("<tr class=\"tab3\"><td>");
			                sb.append("<li>浏览本帖隐藏内容需要您花费 <strong>"+topicTypeNum+"</strong> 枚金币！</li>");
			                sb.append("<li>您已经支付过 <strong>"+currenyPay+"</strong> 枚金币！</li>");			               
			                sb.append("</td></tr>");
			                sb.append("</table>");
			                if(content.indexOf("[tcontent]")>=0)
			                {	
			    	            content = content.replaceAll("\\[tcontent\\]","");
			    	     	    content = content.replaceAll("\\[/tcontent\\]","");
			                }
				}				
				else	//没有购买过或付款额小于帖子需要的金币数
				{
							StringBuilder temp = new StringBuilder(200);                
							temp.append("<form action=\"\" method=\"post\"><table width=\"280\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\"bg1\">");
							temp.append("<tr class=\"tab1\"><td>");
							temp.append("<img border=\"0\" alt=\"购买帖,所需金币 " + topicTypeNum + "\" src=\"images/topicPro/money.gif\" align=\"absmiddle\" /><strong>购买贴</strong>");
							temp.append("</td></tr>");
							temp.append("<tr class=\"tab3\"><td>");
							temp.append("<li>浏览本帖隐藏内容需要您花费 <strong>"+topicTypeNum+"</strong> 枚金币！</li>");
							temp.append("<li>您已经支付过 <strong>"+currenyPay+"</strong> 枚金币！</li>");
							temp.append("<div align=\"center\"><input name=\"btnBuy\" type=\"button\" value=\"确定购买\" class=\"btn\" onClick=\"javascript:topicBuy("+topicId+","+currentUserId+","+topicTypeNum+");\"></div>");
							temp.append("</td></tr>");
							temp.append("</form></table>");
			                //隐藏内容
							if(contentLen>0&&content.indexOf("[tcontent]")>=0)
			                {
								content = EncodeString.ubbPattern(content,"\\[tcontent\\](.*?)\\[/tcontent\\]",temp.toString()); 
			                }
				}
			}
			else if(topicType==5) //回复可见
			{				
				ITopicReService topicReService = (ITopicReService)BeanManager.getBean("topicReService");
				int count = topicReService.listCountByReUser(topicId, currentUserId);
				if(count<=0)
				{
					StringBuilder temp = new StringBuilder(200);
					sb.append("<table width=\"280\" border=\"0\" cellpadding=\"2\" cellspacing=\"1\" class=\"bg1\">");
					sb.append("<tr class=\"tab1\" align=\"center\"><td>");
					sb.append("<strong>本贴隐藏内容回复后可见！</strong>");
					sb.append("</td></tr>");
					sb.append("</table>");
					//隐藏内容
					if(contentLen>0&&content.indexOf("[tcontent]")>=0)
	                {
						content = EncodeString.ubbPattern(content,"\\[tcontent\\](.*?)\\[/tcontent\\]",temp.toString()); 
	                }
				}
				else
				{
					if(content.indexOf("[tcontent]")>=0)
	                {	
	    	            content = content.replaceAll("\\[tcontent\\]","");
	    	     	    content = content.replaceAll("\\[/tcontent\\]","");
	                }
				}	
			}
        	sb.append(content);
		}
        else //版主或楼主
        {
        	if(content.indexOf("[tcontent]")>=0)
            {	
	            content = content.replaceAll("\\[tcontent\\]","");	    	           
	     	    content = content.replaceAll("\\[/tcontent\\]","");
            }
        	sb.append(content);
        } 
        int contentCopyright = tbbsTopicContent.getContentCopyright();
        boolean contentUserPen = tbbsTopicContent.getContentUserPen();
        if(contentCopyright==1)	//1.本站独享
        {
        	sb.append("<hr width=\"100%\" size=\"1\" noshade=\"noshade\" />");
            sb.append("作者声明：该文版权归作者个人所有，本站享有独家网络发表权，其他网站、媒体未经许可，不得以任何形式转载！");            
        }
        else if(contentCopyright==2)	//2.网络共享 
        {
        	sb.append("<hr width=\"100%\" size=\"1\" noshade=\"noshade\" />");
            sb.append("作者声明：该文版权为网络共享，大家喜欢的话可以任意转载，传抄……");            
        }
        else if(contentCopyright==3)	//3.非商业性共享
        {
        	sb.append("<hr width=\"100%\" size=\"1\" noshade=\"noshade\" />");
            sb.append("作者声明：该文在未经商业用途的情况下，可任意转载，传抄……");            
        }
        if(contentUserPen)
        {
        	if(!personalSign.trim().equals(""))
	        {
        		//personalSign = EncodeString.htmlEncoder(personalSign);
	        	//personalSign = EncodeString.ubbEncoder(personalSign);
		        sb.append("<hr width=\"100%\" size=\"1\" noshade=\"noshade\" />");
		        sb.append(personalSign);
        	}
        }
		
        sb.append("</DIV>");
        return sb.toString();	
	}	
	
	/**
	 * 得到要引用的主题内容
	 * @param topicReId
	 * @return
	 * @throws Exception
	 */
	public static String getTopicQuoteContent(int topicReId) throws Exception
	{
		StringBuilder sb = new StringBuilder(500);		
		//读取回复内容
		ITopicContentService topicContentService = (ITopicContentService)BeanManager.getBean("topicContentService");
		TbbsTopicContent tbbsTopicContent = topicContentService.load(topicReId);
		String content = tbbsTopicContent.getContent();
        sb.append(content);       
        return sb.toString();
	}
	
	/**
	 * 加当前用户为好友
	 * @param userId
	 * @return
	 */
	public static String getAfficheLink(int affId,String title)
	{
		if(affId<=0)
			return "";
		StringBuilder sb = new StringBuilder(200); 
		sb.append("<span class='ellipsisWord' style='width:100px;'><a onClick=\"return openPop(this,600,400,100,200);\" ");
        sb.append(" href=\"affiche_info.jsp?affId=");        
        sb.append(affId);        
        sb.append("\" target=\"_blank\" ");
        sb.append(" title=\"");
        sb.append(title); 
        sb.append("\">");
        sb.append(title);   
        sb.append("</a></span>");
        return sb.toString();	
	}	
	
	/**
	 * 获得公告信息编码后的内容，支持完整HTML(使用FCKEditor则不用进行此编码工作)
	 * @return
	 */
	public static String getAfficheContent(String content)
	{
		content = EncodeString.htmlEncoderEx(content);   //HTML编码		
		//content = EncodeString.ubbEncoder(content, true, true);      //UBB编码 
		return content;
	}
	
	/**
	 * 版面的链接
	 */
	public static String getClassLink(Integer classId,String className)
	{
		StringBuilder sb = new StringBuilder("<a href=\"class.jsp?classId=");
		sb.append(classId);
		sb.append("\" title=\"");
		sb.append(className);
		sb.append("\">");
		sb.append(className);
		sb.append("</a>");
		return sb.toString();
	}
	
	/**
	 * 新窗口打开主题
	 * @param classId
	 * @param classStyle
	 * @param tbbsTopic
	 * @return
	 */
	public static String getTopicOpenLink(Integer classId,Integer classStyle,TbbsTopic tbbsTopic)
	{
		StringBuilder sb = new StringBuilder("<a href=\"topic_page.jsp?classId=");
		sb.append(classId);
		sb.append("&topicId=");
		sb.append(tbbsTopic.getTopicId());
		sb.append("&classStyle=");
		sb.append(classStyle);		
        sb.append("\" target=\"_blank\">");
        if(tbbsTopic.getTopicOrder()!=null&&tbbsTopic.getTopicOrder().intValue()>0)	//有排序的图标用UP
        {
            sb.append("<img border=\"0\" alt=\"新窗口开启\" src=\"images/topicPro/up1.gif\" align=\"absmiddle\" />");           
        }
        else
        {        	
        	int topicPro = tbbsTopic.getTopicPro()==null?0:tbbsTopic.getTopicPro().intValue();
            switch(topicPro)
            {
                case 1 :	//锁定
                	sb.append("<img border=\"0\" alt=\"新窗口开启\" src=\"images/topicPro/lock.gif\" align=\"absmiddle\" />");
                    break;
                case 2 :	//禁止回复(暂无图标，需增加)
                	sb.append("<img border=\"0\" alt=\"新窗口开启\" src=\"images/topicPro/lock.gif\" align=\"absmiddle\" />");
                    break;
                case 3 :	//精品
                	sb.append("<img border=\"0\" alt=\"新窗口开启\" src=\"images/topicPro/best.gif\" align=\"absmiddle\" />");
                    break;
                default:                    
                    int isAfter = Utility.compareDateInt(tbbsTopic.getTopicAddTime());
                    if(isAfter>0){
                        sb.append("<img border=\"0\" alt=\"新窗口开启\" src=\"images/topicPro/old.gif\" align=\"absmiddle\" />");
                    }else{
                        sb.append("<img border=\"0\" alt=\"新窗口开启\" src=\"images/topicPro/new.gif\" align=\"absmiddle\" />");
                    }               
            }
        }
        sb.append("</a>");
        return sb.toString();
	}
	
	/**
	 * 主题表格标题链接，对象参数
	 * @param tbbsTopic
	 * @return
	 * @throws Exception
	 */
	public static String getTopicLink(TbbsTopic tbbsTopic,int pageIndex) throws Exception
	{
        StringBuilder sb = new StringBuilder();
		if(tbbsTopic.getTopicIsDel().booleanValue())
		{
        	return "<font color=\"#666666\">&lt;该主题已被删除&gt;</font>";
        }
        else if(tbbsTopic.getTopicPro().intValue()==4)
        {
        	return "<font color=\"#ff0000\">==&lt;该主题被禁止显示&gt;==</font>";
        }
        else
        {
	        String topicTitle = tbbsTopic.getTitle();
        	//标题HTML编码 
	        topicTitle = EncodeString.htmlEncoder(topicTitle);
        	//标题文字过滤
	        IContentFilterService contentFilterService = (IContentFilterService)BeanManager.getBean("contentFilterService");
	        List rsList = contentFilterService.listByType(2);
	        TbbsContentFilter tbbsContentFilter = null;
	        for(int i=0;i<rsList.size();i++)
	        {
	        	tbbsContentFilter = (TbbsContentFilter)rsList.get(i);
	        	topicTitle = topicTitle.replaceAll(tbbsContentFilter.getSourceStr(), tbbsContentFilter.getReplaceStr());   	
	        }	
	        //提取标题样式
	        String styleColor = "";	//颜色样式
	        String styleBold = "";	//加粗样式
	        if(tbbsTopic.getTopicStyleList()!=null)
	        {
	        	String[] styles = Utility.spitString(tbbsTopic.getTopicStyleList(), ",");
	        	styleColor = styles[0];
	        	styleBold = styles[1];
	        }
	        //组装开始
	        sb.append("<a href=\"topic_page.jsp?classId=");
	        sb.append(tbbsTopic.getClassId());
	        sb.append("&topicId=");
	        sb.append(tbbsTopic.getTopicId());
	        sb.append("&pageIndex=");
	        sb.append(pageIndex);
	        sb.append("\" target=\"_self\" title=\"");
	        sb.append(topicTitle);
	        sb.append("\">");
	        if(!styleColor.trim().equals("")||!styleBold.trim().equals(""))
	        {
	        	sb.append("<span style=\"");
            	if(!styleColor.equals("")){
            		sb.append("color:");
            		sb.append(styleColor);
            		sb.append(";");
            	}
            	if(styleBold.equals("1")){
            		sb.append("font-weight: bold;");
            	}
            	sb.append("\">");
            	sb.append(topicTitle);
            	sb.append("</span>");
	        }
	        else
	        {
            	sb.append(topicTitle);
            }
            sb.append("</a>");
        }
		return sb.toString();
	}
	
	/**
	 * 主题标题链接,值参数
	 * @param tbbsTopic
	 * @return
	 * @throws Exception
	 */
	public static String getTopicLink(int classId,int topicId,int topicPro,String title,String topicStyleList,boolean topicIsDel,int displayLen,int pageIndex) throws Exception
	{
        StringBuilder sb = new StringBuilder();
		if(topicIsDel)
		{
        	return "<font color=\"#666666\">&lt;该主题已被删除&gt;</font>";
        }
        else if(topicPro==4)
        {
        	return "<font color=\"#ff0000\">==&lt;该主题被禁止显示&gt;==</font>";
        }
        else
        {	
	        String topicTitle = title;
        	//标题HTML编码 
	        topicTitle = EncodeString.htmlEncoder(topicTitle);
        	//标题文字过滤
	        IContentFilterService contentFilterService = (IContentFilterService)BeanManager.getBean("contentFilterService");
	        List rsList = contentFilterService.listByType(2);
	        TbbsContentFilter tbbsContentFilter = null;
	        for(int i=0;i<rsList.size();i++)
	        {
	        	tbbsContentFilter = (TbbsContentFilter)rsList.get(i);
	        	topicTitle = topicTitle.replaceAll(tbbsContentFilter.getSourceStr(), tbbsContentFilter.getReplaceStr());   	
	        }	
	        //提取标题样式
	        String styleColor = "";	//颜色样式
	        String styleBold = "";	//加粗样式
	        if(topicStyleList!=null)
	        {
	        	String[] styles = Utility.spitString(topicStyleList, ",");
	        	styleColor = styles[0];
	        	styleBold = styles[1];
	        }
	        //组装开始
	        sb.append("<a href=\"topic_page.jsp?classId=");
	        sb.append(classId);
	        sb.append("&topicId=");
	        sb.append(topicId);
	        sb.append("&pageIndex=");
	        sb.append(pageIndex);
	        sb.append("\" target=\"_self\" title=\"");
	        sb.append(topicTitle);
	        sb.append("\">");
	        if(displayLen>0)	//如果需要截取字符串
	        	topicTitle = Utility.subTitle(topicTitle, displayLen);	       
	        if(!styleColor.trim().equals("")||!styleBold.trim().equals(""))
	        {
	        	sb.append("<span style=\"");
            	if(!styleColor.equals("")){
            		sb.append("color:");
            		sb.append(styleColor);
            		sb.append(";");
            	}
            	if(styleBold.equals("1")){
            		sb.append("font-weight: bold;");
            	}
            	sb.append("\">");
            	sb.append(topicTitle);
            	sb.append("</span>");
	        }
	        else
	        {
            	sb.append(topicTitle);
            }
            sb.append("</a>");
        }
		return sb.toString();
	}	
	
	/**
	 * 回复表格标题链接
	 * @param tbbsTopicRe
	 * @return
	 * @throws Exception
	 */
	public static String getTopicReLink(TbbsTopicRe tbbsTopicRe,int pageIndex) throws Exception
	{
		StringBuilder sb = new StringBuilder();
		if(tbbsTopicRe.getReIsDel().booleanValue())
		{
        	return "<font color=\"#666666\">&lt;该主题已被删除&gt;</font>";
        }
        else
        {
	        String topicTitle = tbbsTopicRe.getTitle();
        	//标题HTML编码 
	        topicTitle = EncodeString.htmlEncoder(topicTitle);
        	//标题文字过滤
	        IContentFilterService contentFilterService = (IContentFilterService)BeanManager.getBean("contentFilterService");
	        List rsList = contentFilterService.listByType(2);
	        TbbsContentFilter tbbsContentFilter = null;
	        for(int i=0;i<rsList.size();i++)
	        {
	        	tbbsContentFilter = (TbbsContentFilter)rsList.get(i);
	        	topicTitle = topicTitle.replaceAll(tbbsContentFilter.getSourceStr(), tbbsContentFilter.getReplaceStr());   	
	        }	
	        //提取标题样式
	        String styleColor = "";	//颜色样式
	        String styleBold = "";	//加粗样式
	        if(tbbsTopicRe.getReStyleList()!=null)
	        {
	        	String[] styles = Utility.spitString(tbbsTopicRe.getReStyleList(), ",");
	        	styleColor = styles[0];
	        	styleBold = styles[1];
	        }
	        //组装开始
	        sb.append("<a href=\"topic_page.jsp?classId=");
	        sb.append(tbbsTopicRe.getClassId());
	        sb.append("&topicId=");
	        sb.append(tbbsTopicRe.getTopicId());
	        sb.append("&topicReId=");
	        sb.append(tbbsTopicRe.getTopicReId());
	        sb.append("&pageIndex=");
	        sb.append(pageIndex);
	        sb.append("\" target=\"_self\">");
	        if(!styleColor.equals("")||!styleBold.equals(""))
	        {
	        	sb.append("<span style=\"");
            	if(!styleColor.equals("")){
            		sb.append("color:");
            		sb.append(styleColor);
            		sb.append(";");
            	}
            	if(styleBold.equals("1")){
            		sb.append("font-weight: bold;");
            	}
            	sb.append("\">");
            	sb.append(topicTitle);
            	sb.append("</span>");
	        }
	        else
	        {
            	sb.append(topicTitle);
            }
            sb.append("</a>");
        }
		return sb.toString();
	}
	
	/**
	 * 回复表格标题链接
	 * @param tbbsTopicRe
	 * @return
	 * @throws Exception
	 */
	public static String getTopicReLink(int classId,int topicId,int topicReId,int rePro,String topicTitle,String reStyleList,boolean reIsDel,int displayLen,int pageIndex) throws Exception
	{
        StringBuilder sb = new StringBuilder();
		if(reIsDel)
		{
        	return "<font color=\"#666666\">&lt;该主题已被删除&gt;</font>";
        }
        else
        {
	        //标题HTML编码 
	        topicTitle = EncodeString.htmlEncoder(topicTitle);
        	//标题文字过滤
	        IContentFilterService contentFilterService = (IContentFilterService)BeanManager.getBean("contentFilterService");
	        List rsList = contentFilterService.listByType(2);
	        TbbsContentFilter tbbsContentFilter = null;
	        for(int i=0;i<rsList.size();i++)
	        {
	        	tbbsContentFilter = (TbbsContentFilter)rsList.get(i);
	        	topicTitle = topicTitle.replaceAll(tbbsContentFilter.getSourceStr(), tbbsContentFilter.getReplaceStr());   	
	        }	
	        //提取标题样式
	        String styleColor = "";	//颜色样式
	        String styleBold = "";	//加粗样式
	        String[] styles = Utility.spitString(reStyleList, ",");
	        styleColor = styles[0];
	        styleBold = styles[1];	        
	        //组装开始
	        sb.append("<a href=\"topic_page.jsp?classId=");
	        sb.append(classId);
	        sb.append("&topicId=");
	        sb.append(topicId);
	        sb.append("&topicReId=");
	        sb.append(topicReId);
	        sb.append("&pageIndex=");
	        sb.append(pageIndex);
	        sb.append("\" target=\"_self\">");
	        if(!styleColor.equals("")||!styleBold.equals(""))
	        {
	        	sb.append("<span style=\"");
            	if(!styleColor.equals("")){
            		sb.append("color:");
            		sb.append(styleColor);
            		sb.append(";");
            	}
            	if(styleBold.equals("1")){
            		sb.append("font-weight: bold;");
            	}
            	sb.append("\">");
            	sb.append(topicTitle);
            	sb.append("</span>");
	        }
	        else
	        {
            	sb.append(topicTitle);
            }
            sb.append("</a>");
        }
		return sb.toString();
	}	
		
	
	/**
	 * 主题列表：是否为热门主题图标显示
	 * @param isHotTopic
	 * @param isHotRe
	 * @param topicViewCount
	 * @param topicReCount
	 * @return
	 */
	public static String getTopicHotDisplay(int isHotTopic,int isHotRe,int topicViewCount,int topicReCount)
	{
		String ret = "";
		if((isHotTopic!=0 && topicViewCount >= isHotTopic) || (isHotRe!=0 && topicReCount>=isHotRe))
        {
            ret = "<img border=\"0\" alt=\"热门主题\" src=\"images/topicPro/hot.gif\" align=\"absmiddle\" />";
        }
		return ret;
	}
	
	/**
	 * 主题列表：主题心情图标显示
	 * @param topicMood
	 * @return
	 */
	public static String getTopicMoodDisplay(Integer topicMood)
	{
		String ret = "<img src=\"images/mood/"+topicMood+".gif\" border=\"0\"  align=\"absmiddle\" alt=\"心情\"></img>";
		return ret;
	}
	
	/**
	 * 主题列表：主题内容长度显示
	 * @param topicId
	 * @param topicReId
	 * @param topicLen
	 * @param linkFlag	是否链接至回复页面
	 * @return
	 */
	public static String getTopicLenDisplay(int classId,int topicId,int topicReId,int topicLen,boolean linkFlag)
	{
		StringBuilder sb = new StringBuilder(100);
		if(linkFlag)
		{	
			sb.append("<a href=\"topic_re.jsp?classId=");			
			sb.append(classId);
			sb.append("&topicId=");
			sb.append(topicId);
			sb.append("&topicReId=");
			sb.append(topicReId);
			sb.append("\">");
		}	
		sb.append("<span style=\"color:#000099\">");
		sb.append(topicLen);
		sb.append(" chars</span>");
		if(linkFlag)
		{
			sb.append("</a>");   
		}	
        return sb.toString();
	}
	
	/**
	 * 主题列表：主题类型图标显示
	 * @param topicType
	 * @return
	 */
	public static String getTopicTypeDisplay(Integer topicType,BigDecimal topicTypeNum)
	{
        StringBuilder sb = new StringBuilder(100);
		switch(topicType.intValue())
        {
	        case 2:
	            sb.append("<img border=\"0\" onmouseover=\"showlayer(event, '"+ topicTypeNum +"分可见帖') ;\" onmouseout=\"hidelayer();\" src=\"images/topicPro/mark.gif\" align=\"absmiddle\" />");
	            break;
	        case 3:
	            sb.append("<img border=\"0\" onmouseover=\"showlayer(event, '"+ topicTypeNum +"金币购买帖') ;\" onmouseout=\"hidelayer();\"  src=\"images/topicPro/money.gif\" align=\"absmiddle\" />");
	            break;
	        case 4:
	            sb.append("<img border=\"0\" onmouseover=\"showlayer(event, '"+ topicTypeNum +"分求助帖') ;\" onmouseout=\"hidelayer();\"  src=\"images/topicPro/help.gif\" align=\"absmiddle\" />");
	            break;
	        case 5:
	            sb.append("<img border=\"0\"  onmouseover=\"showlayer(event, '隐藏内容回复后可见') ;\" onmouseout=\"hidelayer();\" src=\"images/topicPro/hide.gif\" align=\"absmiddle\" />");
	            break;
	        case 6:
	            sb.append("<img border=\"0\"  onmouseover=\"showlayer(event, '"+ topicTypeNum +"分求助帖&lt;已经结贴&gt;') ;\" onmouseout=\"hidelayer();\" src=\"images/topicPro/helpok.gif\" align=\"absmiddle\" />");
	            break; 
        }
		return sb.toString();
	}
	
	/**
	 * 主题列表中点击查看回复的按钮封装
	 * @param classId
	 * @param topicId
	 * @return
	 */
	public static String getTopicReTree(Integer classId,Integer topicId)
	{
		StringBuilder sb = new StringBuilder("<img id=\"icon_");
		sb.append(topicId);
		sb.append("\" onclick=\"javascript:loadTree(");
		sb.append(topicId);
		sb.append(",'inc/topic_re_tree.jsp?classId=");
		sb.append(classId);
		sb.append("&topicId=");
		sb.append(topicId);
		sb.append("');\" alt=\"点击展开本主题所有回复\"   src=\"images/tree/t1.gif\" align=\"absmiddle\"  style=\"cursor:hand;\" />");
		return sb.toString();		
	}
	
	
	public static String getTopicReTreeDisplay(int i,int size)
	{
		StringBuilder sb = new StringBuilder(100);
        if(i<size-1)
        {
        	sb.append("<span class=\"pageTree\">├</span>");
        	
        }else{
        	sb.append("<span class=\"pageTree\">└</span>");
        }              
        return sb.toString();
	}
	
	/**
	 * 主题列表：主题心情图标显示
	 * @param topicMood
	 * @return
	 */
	public static String getTopicIlikeDisplay(Date lastDatetime,Date lastReDatetime)	
	{
		String ret = "";
        if(lastReDatetime==null)
        {
            ret = "<img src=\"images/topicPro/old.gif\" border=\"0\" align=\"absmiddle\" />";
        }    
        else if(lastReDatetime.after(lastDatetime)){			
        	ret = "<img src=\"images/topicPro/new.gif\" border=\"0\" align=\"absmiddle\" />";                
        }else{
        	ret = "<img src=\"images/topicPro/old.gif\" border=\"0\" align=\"absmiddle\" />";
        } 		
		return ret;
	}	
/******************************************************************/	
	
	/**
	 * 年份列表
	 */
	public static String listYears()
	{
		StringBuilder sb = new StringBuilder(200);
		for(int i=1940;i<=2046;i++)
		{
			appendOptions(sb,i,i+"年",2000);
		}	
		return sb.toString();
	}
	
	/**
	 * 月份列表
	 */
	public static String listMonths(int year)
	{
		StringBuilder sb = new StringBuilder(200);
		for(int i=1;i<13;i++)
		{
			appendOptions(sb,i,i+"月",1);
		}	
		return sb.toString();
	}
	
	/**
	 * 日列表
	 */
	public static String listDays(int year,int month)
	{
		StringBuilder sb = new StringBuilder(200);
		for(int i=1;i<13;i++)
		{
			appendOptions(sb,i,i+"月",1);
		}	
		return sb.toString();
	}
	
/*************************************************************/	

	
/********************* 下拉菜单 *******************************/	
	
	public static String booleanOptions(boolean defaultValue)
	{
		
		StringBuilder sb = new StringBuilder();
		sb.append("<option value=0");
		if(!defaultValue)
			sb.append(" selected");
		sb.append(">否</option>");
		sb.append("<option value=1");
		if(defaultValue)
			sb.append(" selected");
		sb.append(">是</option>");		
		return sb.toString();
	}	
	
	
	
	
	
	/**
	 * 根据参数类型获取字典列表
	 * @param dictType
	 * @return
	 */
	public static String getDictParamOptions(String dictType,Integer defaultValue) throws BusiException
	{		
        StringBuilder sb = newStringBuilder();
		try
		{
			IDictParamService dictParamService = (IDictParamService)BeanManager.getBean("dictParamService");
			List list = dictParamService.listByType(dictType);
			TbbsDictParam obj = null;
			for(int i=0;i<list.size();i++)
			{
				obj = (TbbsDictParam)list.get(i);
				appendOptions(sb,obj.getDictValue().intValue(),obj.getDictContent(),defaultValue);
			}
		}
		catch(Exception e)
		{
			logger.error(e);
            throw new BusiException("读取参数信息失败！",e);
		}
		return sb.toString();
	}
	
	/**
	 * 根据参数类型获取字典列表,没有请选择
	 * @param dictType
	 * @return
	 */
	public static String getDictParamOptionsNo(String dictType,int defaultValue)
	{
		StringBuilder sb = new StringBuilder(200);
		try
		{
			IDictParamService dictParamService = (IDictParamService)BeanManager.getBean("dictParamService");
			List list = dictParamService.listByType(dictType);
			TbbsDictParam obj = null;
			for(int i=0;i<list.size();i++)
			{
				obj = (TbbsDictParam)list.get(i);
				appendOptions(sb,obj.getDictValue().intValue(),obj.getDictContent(),defaultValue);
			}
		}
		catch(Exception e)
		{
			logger.error(e);
		}
		return sb.toString();
	}	
	
	public static String getContentFilterTypeOptions(int filterType)
	{
		StringBuilder sb = newStringBuilder();
		appendOptions(sb,1,"用户名",filterType);
		appendOptions(sb,2,"发帖主题",filterType);
		appendOptions(sb,3,"发帖内容",filterType);
		appendOptions(sb,4,"短消息主题",filterType);
		appendOptions(sb,5,"短消息内容",filterType);
		appendOptions(sb,6,"签名档内容",filterType);
		return sb.toString();
	}
	
	/**
	 * 电子邮件是否公公开选项
	 * @param emailOpenFlag
	 * @return
	 */
	public static String getEmailOpenFlagOptions(String emailOpenFlag)
	{
		StringBuilder sb = newStringBuilder();
		appendOptions(sb,"0","社区内公开",emailOpenFlag);
		appendOptions(sb,"1","仅对好友公开",emailOpenFlag);
		appendOptions(sb,"2","完全保密",emailOpenFlag);
		return sb.toString();
	}	
    
    
    /**
     * 主题查询状态
     * @param listType
     * @return
     */
    public static String getListTypeOptions(int listType)
    {
        StringBuilder sb = new StringBuilder();
        appendOptions(sb,0,"全部主题",listType);
        appendOptions(sb,1,"已认证主题",listType);
        appendOptions(sb,2,"未认证主题",listType);
        appendOptions(sb,3,"回收站主题",listType);
        return sb.toString();
    }
	
	/**
	 * 获得省、直辖市地区列表
	 * @param areaType
	 * @param defaultValue
	 * @return
	 */
	public static String getProvinceOptions(int defaultValue)
	{
		StringBuilder sb = newStringBuilder();
		try
		{
			IAreaService areaService = (IAreaService)BeanManager.getBean("areaService");
			List list = areaService.listByType(1);
			TbbsArea obj = null;
			for(int i=0;i<list.size();i++)
			{
				obj = (TbbsArea)list.get(i);
				appendOptions(sb,obj.getAreaId().intValue(),obj.getAreaName(),defaultValue);
			}
		}
		catch(Exception e)
		{
			logger.error(e);
		}
		return sb.toString();
	}	
	
	/**
	 * 获得管理员等级列表
	 * @param defaultValue
	 * @return
	 */
	public static String getMasterGradeOptions(int defaultValue)
	{
		StringBuilder sb = new StringBuilder();
		try
		{
			IMasterGradeService masterGradeService = (IMasterGradeService)BeanManager.getBean("masterGradeService");
			List list = masterGradeService.listAll();
			TbbsMasterGrade obj = null;
			for(int i=0;i<list.size();i++)
			{
				obj = (TbbsMasterGrade)list.get(i);
				appendOptions(sb,obj.getMgId().intValue(),obj.getGradeName(),defaultValue);
			}
		}
		catch(Exception e)
		{
			logger.error(e);
		}
		return sb.toString();
	}
	
	/**
	 * 获得用户等级列表
	 * @param defaultValue
	 * @return
	 */
	public static String getUserGradeOptions(int defaultValue)
	{
		StringBuilder sb = new StringBuilder(100);
        appendOptions(sb,0,"全部",defaultValue);
		try
		{
			IUserGradeService userGradeService = (IUserGradeService)BeanManager.getBean("userGradeService");
			List list = userGradeService.listAll();
			TbbsGrade obj = null;
			for(int i=0;i<list.size();i++)
			{
				obj = (TbbsGrade)list.get(i);
				appendOptions(sb,obj.getGradeId().intValue(),obj.getGradeName(),defaultValue);
			}
		}
		catch(Exception e)
		{
			logger.error(e);
		}
		return sb.toString();
	}
	
	/**
	 * 获得有效用户列表
	 * @param defaultValue
	 * @return
	 */
	public static String getActiveUserOptions(int defaultValue)
	{
		StringBuilder sb = new StringBuilder(200);
		try
		{
			IUserService userService = (IUserService)BeanManager.getBean("userService");
			List list = userService.listAllActive();
			TbbsUserInfo obj = null;
			for(int i=0;i<list.size();i++)
			{
				obj = (TbbsUserInfo)list.get(i);
				appendOptions(sb,obj.getUserId().intValue(),obj.getLoginId()+"-"+obj.getUserName(),defaultValue);
			}
		}
		catch(Exception e)
		{
			logger.error(e);
		}
		return sb.toString();
	}
    
    /**
     * 获得不是指定版面黑名单的有效用户列表.
     * 
     * @param classId 版面ID
     * @param defaultValue 默认值
     * 
     * @return the active user options
     */
    public static String getClassActiveUserOptions(int classId,int defaultValue) throws BusiException
    {
        StringBuilder sb = new StringBuilder(200);
        try
        {
            IUserService userService = (IUserService)BeanManager.getBean("userService");
            List list = userService.listAllClassActive(classId);
            TbbsUserInfo obj = null;
            for(int i=0;i<list.size();i++)
            {
                obj = (TbbsUserInfo)list.get(i);
                appendOptions(sb,obj.getUserId().intValue(),obj.getLoginId()+"-"+obj.getUserName(),defaultValue);
            }
        }
        catch(Exception e)
        {
            logger.error(e);
            throw new BusiException(e);
        }
        return sb.toString();
    } 
	
	/**
	 * 根据用户等级获得有效用户列表
	 * @param gradeId
	 * @param defaultValue
	 * @return
	 */
	public static String getActiveGradeUserOptions(int gradeId,int defaultValue)
	{
		StringBuilder sb = newStringBuilder();
		try
		{
			IUserService userService = (IUserService)BeanManager.getBean("userService");
			List list = userService.listAllActiveByGrade(gradeId);
			TbbsUserInfo obj = null;
			for(int i=0;i<list.size();i++)
			{
				obj = (TbbsUserInfo)list.get(i);
				appendOptions(sb,obj.getUserId().intValue(),obj.getLoginId(),defaultValue);
			}
		}
		catch(Exception e)
		{
			logger.error(e);
		}
		return sb.toString();
	}
	
	/**
	 * 根据用户等级获得有效用户列表(多个等级用逗号分开)
	 * @param gradeIds
	 * @param defaultValue
	 * @return
	 */
	public static String getActiveGradeUserOptions(String gradeIds,int defaultValue)
	{
		StringBuilder sb = newStringBuilder();
		try
		{
			IUserService userService = (IUserService)BeanManager.getBean("userService");
			List list = userService.listAllActiveByGrade(gradeIds);
			TbbsUserInfo obj = null;
			for(int i=0;i<list.size();i++)
			{
				obj = (TbbsUserInfo)list.get(i);
				appendOptions(sb,obj.getUserId().intValue(),obj.getLoginId(),defaultValue);
			}
		}
		catch(Exception e)
		{
			logger.error(e);
		}
		return sb.toString();
	}			
	
	/**
	 * 获得分类列表,后台
	 * @param defaultValue
	 * @return
	 */
	public static String getClassOptions(int defaultValue)
	{
		StringBuilder sb = new StringBuilder(500);
		
		List<Map> rsList = (List<Map>)OSCacheManager.loadCacheObject("CLASS_OPTIONS");
		if(rsList==null)
		{	
			
			IClassService classService = (IClassService)BeanManager.getBean("classService");
			
			try
			{
				rsList = classService.listClassByType(0,null);//递归查询所有结果				
		    	OSCacheManager.storeCacheObject("CLASS_OPTIONS", rsList);
			}
			catch(Exception e)
			{
				logger.error(e);
			}
		}
		Map rsMap = null;
    	for(int i=0;i<rsList.size();i++)
    	{
    		rsMap = rsList.get(i);
    		appendOptions(sb,((Integer)rsMap.get("CLASS_ID")).intValue(),(String)rsMap.get("CLASS_NAME"),defaultValue);		    		
    	}
		
		return sb.toString();
	}	

	/**
	 * 获得分类/版面列表,后台
	 * @param defaultValue
	 * @return
	 */
	public static String getAllClassOptions(int defaultValue)
	{
		StringBuilder sb = new StringBuilder(500);
		
		List<Map> rsList = (List<Map>)OSCacheManager.loadCacheObject("ALL_CLASS_OPTIONS");
		if(rsList==null)
		{			
			IClassService classService = (IClassService)BeanManager.getBean("classService");
			try
			{
				rsList = classService.listClassByType(null,null);//递归查询所有结果				
		    	OSCacheManager.storeCacheObject("ALL_CLASS_OPTIONS", rsList);
			}
			catch(Exception e)
			{
				logger.error(e);
			}
		}
		Map rsMap = null;
    	for(int i=0;i<rsList.size();i++)
    	{
    		rsMap = rsList.get(i);
    		appendOptions(sb,((Integer)rsMap.get("CLASS_ID")).intValue(),(String)rsMap.get("CLASS_NAME"),defaultValue);		    		
    	}		
		return sb.toString();
	}
    
    /**
     * 获得分类或版面列表.
     * 
     * @param value 当前值
     * @param classType 分类版面类型：0-分类,1-版面
     * 
     * @return 分类或版面列表
     */
    public static String getClassOptions(int classType,int value)
    {
        StringBuilder sb = new StringBuilder(500);
        
        List<Map> rsList = (List<Map>)OSCacheManager.loadCacheObject("CLASS_OPTIONS");
        if(rsList==null)
        {   
            
            IClassService classService = (IClassService)BeanManager.getBean("classService");
            
            try
            {
                rsList = classService.listClassByType(classType,null);//递归查询所有结果                
                OSCacheManager.storeCacheObject("CLASS_OPTIONS", rsList);
            }
            catch(Exception e)
            {
                logger.error(e);
            }
        }
        Map rsMap = null;
        for(int i=0;i<rsList.size();i++)
        {
            rsMap = rsList.get(i);
            appendOptions(sb,((Integer)rsMap.get("CLASS_ID")).intValue(),(String)rsMap.get("CLASS_NAME"),value);                 
        }
        
        return sb.toString();
    }    
	
	/**
	 * 获得用户头像列表
	 * @param areaType
	 * @param defaultValue
	 * @return
	 */
	public static String getUserHeadsOptions(String basePath,String loginId,String defaultValue)
	{
		StringBuilder sb = newStringBuilder();
		try
		{			
			//搜索upfiles/用户名/userHeads下所有图片			
			File dir = new File(Arguments.getRootPath()+"upfiles"+File.separator+loginId+File.separator+"userHeads");
			if(!dir.exists())
				dir.mkdirs();
			File[] files = dir.listFiles(new OnlyExt("gif,jpg,jpeg,bmp,png"));
			String url = "";			
			for(int i=0;i<files.length;i++)
			{				
				url = basePath+"upfiles/"+loginId+"/userHeads/"+files[i].getName();				
				if(i==0)
					appendOptions(sb,url,"=== 自定义头像 ===",defaultValue);	
				appendOptions(sb,url,"自定义头像"+(i+1),defaultValue);
			}
			//搜索images/userHeads下所有图片
			dir = new File(Arguments.getRootPath()+"club"+File.separator+"images"+File.separator+"userHeads");
			if(!dir.exists())
				dir.mkdirs();
			files = dir.listFiles(new OnlyExt("gif,jpg,jpeg,bmp,png"));
			url = "";
			for(int i=0;i<files.length;i++)
			{
				url = basePath+"club/images/userHeads/"+files[i].getName();
				if(i==0)
					appendOptions(sb,url,"=== 系统头像 ===",defaultValue);
				appendOptions(sb,url,files[i].getName(),defaultValue);
			}
		}
		catch(Exception e)
		{
			logger.error(e);
		}
		return sb.toString();
	}	

	
//-------------------------- 下拉列表区域结束 ----------------------------
//-------------------------- 单选按钮组区域开始 --------------------------	

	public static void appendRadio(StringBuilder sb,String name, int value, String text, int defvalue)
	{
		sb.append("<input type=\"radio\" name=\"");
		sb.append(name);		
		sb.append("\" value=\"");
		sb.append(value);
		sb.append("\" ");
		if(value==defvalue)
			sb.append("checked");
		sb.append(">");
		sb.append(text);
		sb.append("&nbsp;&nbsp;");
	}
	
	public static void appendRadio(StringBuilder sb,String name, String value, String text, String defvalue)
	{
		sb.append("<input type=\"radio\" name=\"");
		sb.append(name);		
		sb.append("\" value=\"");
		sb.append(value);
		sb.append("\" ");
		if(value.equals(defvalue))
			sb.append("checked");
		sb.append("/>");
		sb.append(text);
		sb.append("&nbsp;&nbsp;");
	}	
	
	/**
	 * 主题类型的单选框组
	 * @param topicType
	 * @return
	 */
	public static String getTopicTypeRadioOptions(int topicType)
	{
		StringBuilder sb = newStringBuilder();
		appendRadio(sb,"topicType",1,"普通帖",topicType);
		appendRadio(sb,"topicType",2,"积分浏览",topicType);
		appendRadio(sb,"topicType",3,"金币购买 ",topicType);
		appendRadio(sb,"topicType",4,"散分求助",topicType);
		appendRadio(sb,"topicType",5,"回复可见",topicType);		
		return sb.toString();
	}
	
	/**
	 * 获得主题心情的单选框组
	 * @param topicMood
	 * @return
	 */
	public static String getTopicMoodRadioOptions(String topicMood)
	{	
		StringBuilder sb = newStringBuilder();
		return sb.toString();
	}
	
//-------------------------- 单选按钮组区域结束 --------------------------		
/*******************根据参数值得到参数内容*******************************/

	/**
	 * 从缓存MAP中根据参数值获得参数内容
	 */
	public static String getDictParamName(String dictType)
	{		
		Map map = (Map)OSCacheManager.loadCacheObject("DICT_PARAM");
		return Utility.trimNull(map.get(dictType),"未知");
	}
	
	public static String getSexCN(String sex)
	{
		if(sex.equals("F"))
			return "女";
		else if(sex.equals("M"))
			return "男";
		else
			return "保密";
	}
	
	/**
	 * 获得用户等级的名称
	 * @param gradeId
	 * @return
	 */
	public static String getUserGradeName(Integer gradeId) throws Exception
	{
		String ret = "";
		IUserGradeService userGradeService = (IUserGradeService)BeanManager.getBean("userGradeService");
		TbbsGrade tbbsGrade = userGradeService.load(gradeId);
		ret = tbbsGrade.getGradeName();
		tbbsGrade = null;		
		return ret;		
	}	
	
	/**
	 * 根据传入的值获得RADIO的选中状态
	 * @param value
	 * @return
	 */
	public static String getRadioStatus(String value,String value2)
	{
		if(value!=null&&!value.equals("")&&value.equals(value2))
			return "checked";
		else
			return "";
	}
	
	public static String getRadioStatus(Boolean value,boolean value2)
	{
		if(value!=null&&value.booleanValue()==value2)
			return "checked";
		else
			return "";
	}	
	
	
	
/***********************************************************/	
    

    
    
    
	/**
	 * @param args
	 */
	public static void main(String[] args) {

		System.out.println(getTopicReTreeDisplay(4,12));
	}

}
